/* Copyright 2009 Requirements Management System 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.mags.remas.app;


import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.ICoolBarManager;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;
import org.mags.remas.view.commons.ImageProvider;

/**
 * 
 * @author Mario Gaitan
 *
 */
public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
    public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
        super(configurer);
    }
    public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) {
        return new ApplicationActionBarAdvisor(configurer);
    }
	public void postWindowOpen() {
    	PlatformUI.getWorkbench().getDisplay().getActiveShell().setMaximized(true);
    	PlatformUI.getWorkbench().getDisplay().getActiveShell().setImage(ImageProvider.getCommonImage("main.png"));
		IMenuManager menuManager = getWindowConfigurer().getActionBarConfigurer().getMenuManager();
		IContributionItem[] items = menuManager.getItems();
		for (int i = 0; i < items.length; i++) {
			if (items[i].getId().equals("navigate") ||
			items[i].getId().equals("additions") || 
			items[i].getId().equals("org.eclipse.search.menu")){
				menuManager.remove(items[i].getId());
				menuManager.update(true);
			}
		}    	
		ICoolBarManager coolBarManager = getWindowConfigurer().getActionBarConfigurer().getCoolBarManager();
		items=coolBarManager.getItems();
		for (int i = 0; i < items.length; i++) {
			if (items[i].getId().equals("org.eclipse.ui.edit.text.actionSet.annotationNavigation") ||
				items[i].getId().equals("org.eclipse.search.searchActionSet") ||	
				items[i].getId().equals("org.eclipse.ui.edit.text.actionSet.navigation")){
					coolBarManager.remove(items[i].getId());
					coolBarManager.update(true);
				}			
		}
    }
    public void preWindowOpen() {
        IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
        configurer.setInitialSize(new Point(800, 600));
        configurer.setShowCoolBar(true);
        configurer.setShowStatusLine(false);
        configurer.setTitle(Platform.getProduct().getName()+", Version "+Platform.getProduct().getDefiningBundle().getVersion());
    }
}
